package com.jdjt.dams.web;

import java.util.Map;

import com.base.app.AbstractJsonController;
import com.base.common.utils.map.MapUtil;
import com.base.shiro.web.validator.ResourceValidator;
import com.jdjt.dams.entity.DocCateModel;
import com.jdjt.dams.entity.DocCateRangeModel;
import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Page;


/**
 * ResourceController
 * 
 * @author xpg
 * @since 0.1
 */
public class DocCateRangeController extends AbstractJsonController {
	public void index() {
		render("docCateRangeList.jsp");
	}

	public void docCateRangeList() {

		// DocumentModel doc=getModel(DocumentModel.class,"docModel");
		// int start=(getParaToInt("start")!=0)?getParaToInt("start"):1;
		int pageNumber = (getParaToInt("pageIndex") != 0) ? getParaToInt("pageIndex") + 1 : 1;
		int pageSize = (getParaToInt("limit") != 0) ? getParaToInt("limit") : 10;
		Page<DocCateRangeModel> docList = DocCateRangeModel.dao.getCateRangeList(pageNumber, pageSize, getPara("name"));
		Map<String, Object> map = MapUtil.toModel("rows", docList);
		// map.put("rows",goodsModelList.getList() );
		map.put("results", docList.getTotalRow());
		map.put("hasError", false);
		renderJson(map);
	}	

	public void add() {
		render("docCateAdd.jsp");
	}

	public void edit() {
		setAttr("docCate", DocCateModel.dao.findById(getParaToInt()));
		render("docCateEdit.jsp");
	}

	public void view() {
		setAttr("docCate", DocCateModel.dao.findById(getParaToInt()));
		render("docCateView.jsp");
	}

	@Before(ResourceValidator.class)
	public void save() {
		getModel(DocCateModel.class).save();
		redirect("/ms/docCate");
	}

	@Before(ResourceValidator.class)
	public void update() {
		getModel(DocCateModel.class).update();
		redirect("/ms/docCate");
	}

	public void delete() {
		DocCateModel.dao.deleteById(getParaToInt());
		redirect("/ms/docCate");
	}
}
